//给定两个以排序表L1 L2，只使用基本的操作编写计算L1 与 L2的并集


#include<iostream>
#include<list>
#include<vector>
using namespace std;


list<int> myAnd(list<int> &a, list<int> &b){
    list<int> result;
    auto p1 = a.begin();
    auto p2 = b.begin();
/*    while (p1!=a.end() || p2!=b.end())
    {
        if(*p1 == *p2){
            result.push_back(*p1);
            p1++;
            p2++;
        }
        else if(*p1 < *p2){
            
            result.push_back(*p1);
            p1++;

        }
        else{
            result.push_back(*p2);
            p2 ++;
        }
    }*/
    
    for(auto &i : a){
        auto c = new auto(i);
        result.push_back(*c);


    }
    while(p2!=b.end()){
        if(*p1 == *p2){
            
            p1++;
            p2++;
        }
        else if(*p1 < *p2){
            
            
            p1++;

        }
        else{
            result.push_front(*p2);
            p2 ++;
        }
    }
    
    
    



    return result;

    

}

int main(int argc, char *argv[])
{
    
    
    list<int> a{1,2,3,4,5};
    list<int> b{2,4,5,8};
    auto c = myAnd(b,a);
    for(auto i = c.begin();i!=c.end();i++){
        cout << *i<< " ";

    }
    cout << endl;
    return 0;
}
